package cn.nabaixin.sign;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import cn.nabaixin.R;
import cn.nabaixin.utils.AppUtils;
/**
 * 点击场所进入的签到界面
 * @author ZWH
 *
 */
public class SignInActivity extends Activity {
	private ListView lv;
	private SimpleAdapter sa;
	private List<Map<String, Object>> data;
	private TextView refreshView;
	private TextView refreshTimeView;
	private View headerView;
	private TextView footView;
	private View bossPanel;
	private Context c;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sign_in);
		
		c = SignInActivity.this;
		initViews();
		initListener();
		initData();
	}

	private void initViews() {
		lv = (ListView) findViewById(R.id.sign_in_list);
		lv.setBackgroundColor(Color.WHITE);
		lv.setCacheColorHint(0);
		headerView = getLayoutInflater().inflate(R.layout.latest_list_header, null);
		bossPanel = headerView.findViewById(R.id.sign_in_boss);
		bossPanel.setVisibility(View.VISIBLE);
		footView = new TextView(c);
		footView.setText("加载更多...");
		footView.setId(10);
		footView.setHeight(80);
		footView.setGravity(Gravity.CENTER);
		lv.addHeaderView(headerView);
		lv.addFooterView(footView);
	}

	private void initListener() {
		
	}

	private void initData() {
		
		String names[] = new String[]{"张三", "李四", "王五"};
		String actions[] = new String[]{"成为地主", "签到"};
		String sendTiems[] = new String[]{"一周前", "两天前", "一天前", "上午", };
		
		data = new ArrayList<Map<String,Object>>();
		for(int i=0; i<7; i++){
			HashMap<String, Object> item = new HashMap<String, Object>();
			item.put("name", AppUtils.getRandomItem(names));
			item.put("sendtiem", AppUtils.getRandomItem(sendTiems));
			item.put("action", AppUtils.getRandomItem(actions));
			data.add(item);
		}
		sa = new SimpleAdapter(c, data, R.layout.sign_in_list_item, 
				new String[]{"name", "sendtiem", "action"}, 
				new int[]{R.id.sign_in_name, R.id.sign_in_sendTime, R.id.sign_in_action});
		lv.setAdapter(sa);
	}
	
}
